<template>
  <div class="content">
    <div class="center-404">
      <img src="../assets/imgs/404.png" alt="" />

      <div>
        <h3>404</h3>
        <p>Oops... 抱歉，页面不见了...</p>

        <el-button type="primary" size="small" @click="linkTo">
          {{ count }}秒后跳转至首页
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      count: 9,
      timer: null
    }
  },
  mounted() {
    this.timer = setInterval(() => {
      this.count--
      // 如果到了0，就跳转到首页，顺便销毁定时器
      if (this.count <= -1) {
        this.$router.push('/')
        clearInterval(this.timer)
      }
    }, 1000)
  },
  methods: {
    linkTo() {
      this.$router.push('/')
      clearInterval(this.timer)
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.center-404 {
  width: 700px;
  height: 400px;

  display: flex;
  justify-content: center;
  align-items: center;

  img {
    margin-right: 30px;
  }

  h3 {
    font-size: 30px;
    font-weight: normal;
    color: #333;
  }

  p {
    color: #666;
    font-size: 14px;
  }
}
</style>
